package lagou.FileTest;

import java.io.FileWriter;
import java.io.IOException;

public class FileWriterTest {
    public static void main(String[] args) {
        FileWriter file = null;
        try {
            char[] c = new char[]{'1', '2', '3', '4', '5', '6', '7', '8', '9'};
            file = new FileWriter("D:/a.txt", true);//第二个参数代表追加的方式写入，不会覆盖，
            file.write('a');//若文件不存在，创建，若存在，覆盖
            file.write(c, 1, 3);
            file.write(c);
            System.out.println("写入成功");
        } catch (IOException e) {
            throw new RuntimeException(e);
        } finally {
            if (file != null) {
                try {
                    file.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}
